//
//  MessageViewController.m
//  F50
//
//  Created by 郝 巍 on 15/5/6.
//  Copyright (c) 2015年 ZACK. All rights reserved.
//

#import "MessageViewController.h"

@interface MessageViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *dataArray;

}
@end

@implementation MessageViewController
- (void)createBackground
{
    UIImageView *bgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    bgView.image = [UIImage imageNamed:@"background"];
    bgView.userInteractionEnabled = YES;
    [self.view addSubview:bgView];
    
    UIView *nav_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 64)];
    nav_bg.backgroundColor = RGB(59, 107, 178);
    [self.view addSubview:nav_bg];
    
    
    //中间标题
    UILabel *  nav_title=[[UILabel alloc] initWithFrame:CGRectMake(WIDTH/2 - 80, 20, 160, 40)];
    nav_title.text=@"洽谈室";
    nav_title.textAlignment = NSTextAlignmentCenter;
    nav_title.font=[UIFont boldSystemFontOfSize:20];
    nav_title.textColor=[UIColor whiteColor];
    nav_title.backgroundColor=[UIColor clearColor];
    [nav_bg addSubview:nav_title];
    
 
    
    
    
}

- (void)viewWillAppear:(BOOL)animated{
}
-(void)viewDidAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createBackground];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT - 64 -49) style:UITableViewStylePlain];
    
    _tableView.dataSource = self;
    _tableView.delegate = self;
//    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //    _tableView.scrollEnabled = NO; //设置tableview 不能滚动
    _tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
    dataArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];

}

-(void)viewWillDisappear:(BOOL)animated{
//    [self.tabBarItem setBadgeValue:nil];
    
}

#pragma  mark tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return dataArray.count;
}
/// 划动cell是否出现del按钮
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
//
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
//
//           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath      //当在Cell上滑动时会调用此函数
//
//{
//    
//    
//        return  UITableViewCellEditingStyleDelete;  //返回此值时,Cell会做出响应显示Delete按键,点击Delete后会调用下面的函数,别给传递UITableViewCellEditingStyleDelete参数
//  
//    
//}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [dataArray removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
}
/// 自定义划动时del按钮内容
- (NSString *) tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIndentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIndentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    cell.detailTextLabel.text = @"hdkaljsdlasadasd";
    cell.detailTextLabel.textColor = [UIColor whiteColor];
    cell.imageView.image = [UIImage imageWithImageName:@"symbol"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSIndexPath *path = nil;
//    path = [NSIndexPath indexPathForItem:(indexPath.row+1) inSection:indexPath.section];
//    [dataArray insertObject:indexPath atIndex:indexPath.row];
//    [tableView beginUpdates];
//    [tableView insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationMiddle];
//    [tableView endUpdates];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
